import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: 'index',
    meta: {
      title: '数据分析',
      icon: 'file',
      permissions: ['sjfx'],
    },
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '数据分析',
          icon: 'file',
          affix: true,
          // permissions: ['sjfx'],
        },
      },
    ],
  },
  {
    path: '/myjl',
    component: Layout,
    redirect: 'noRedirect',
    //alwaysShow: true,
    name: 'myjl',
    meta: {
      title: '警令管理',
      icon: 'folder',
      permissions: ['jlgl'],
    },
    children: [
      {
        path: 'jlgl',
        name: 'jlgl',
        component: () => import('@/views/jingling/jlgl/index'),
        meta: {
          title: '警令管理',
          icon: 'file',
        },
      },
    ],
  },
  {
    path: '/myjq',
    component: Layout,
    redirect: 'noRedirect',
    //alwaysShow: true,
    name: 'myjq',
    meta: {
      title: '警情管理',
      icon: 'folder',
      permissions: ['jqgl'],
    },
    children: [
      {
        path: 'jqgl',
        name: 'jqgl',
        component: () => import('@/views/jingqing/jlgl/index'),
        meta: {
          title: '警情管理',
          icon: 'file',
        },
      },
    ],
  },
  {
    path: '/xietongfk',
    component: Layout,
    redirect: 'noRedirect',
    //alwaysShow: true,
    name: 'xietongfk',
    meta: {
      title: '警令协同反馈',
      icon: 'folder',
      permissions: ['xtfk'],
    },
    children: [
      {
        path: 'xtfklist',
        name: 'xtfklist',
        component: () => import('@/views/xtfk/fklist/index'),
        meta: {
          title: '警令协同反馈',
          icon: 'file',
        },
      },      
    ],
  },

  {
    path: '/jqxietongfk',
    component: Layout,
    redirect: 'noRedirect',
    //alwaysShow: true,
    name: 'jqxietongfk',
    meta: {
      title: '警情协同反馈',
      icon: 'folder',
      permissions: ['jqxtfk'],
    },
    children: [
      {
        path: 'xtfklist',
        name: 'xtfklist',
        component: () => import('@/views/xtfk/jqfklist/index'),
        meta: {
          title: '警情协同反馈',
          icon: 'file',
        },
      },
    ],
  },
  {
    path: '/myxt',
    component: Layout,
    redirect: 'noRedirect',
    //alwaysShow: true,
    name: 'myxt',
    meta: {
      title: '我的协同任务',
      icon: 'folder',
      permissions: ['myxt'],
    },
    children: [
      {
        path: 'myxt',
        name: 'myxt',
        component: () => import('@/views/xtfk/myfklist/index'),
        meta: {
          title: '我的协同任务',
          icon: 'file',
        },
      },
    ],
  },


  {
    path: '/xietongfkdc',
    component: Layout,
    redirect: 'noRedirect',
    //alwaysShow: true,
    name: 'xietongfkdc',
    meta: {
      title: '协同反馈督察排行',
      icon: 'folder',
      permissions: ['xtfkdcph'],
    },
    children: [
      {
        path: 'xtfkdclist',
        name: 'xtfkdclist',
        component: () => import('@/views/xtfk/paihang/index'),
        meta: {
          title: '协同反馈督察排行',
          icon: 'file',
        },
      },      
    ],
  },
  {
    path: '/sysmanagement',
    component: Layout,
    redirect: 'noRedirect',
    //alwaysShow: true,    
    name: 'sysmanagement',
    meta: {
      title: '基础设置',
      icon: 'folder',
      permissions: ['setting'],
    },
    children: [
      {
        path: 'usernamangement',
        name: 'usernamangement',
        component: () => import('@/views/personnelManagement/userManagement/index'),
        meta: {
          title: '用户管理',
          icon: 'file',
          permissions: ['user'],
        },
      },
      {
        path: 'rolemanagement',
        name: 'rolemanagement',
        component: () => import('@/views/personnelManagement/roleManagement/index'),
        meta: {
          title: '角色管理',
          icon: 'file',
          permissions: ['role'],
        },
      },
      {
        path: 'zzjg',
        name: 'zzjg',
        component: () => import('@/views/personnelManagement/organstrc/index'),
        meta: {
          title: '部门管理',
          icon: 'file',
          permissions: ['dept'],
        },
      },      
      // {
      //   path: 'menumanagement',
      //   name: 'menumanagement',
      //   component: () => import('@/views/personnelManagement/menuManagement/index'),
      //   meta: {
      //     title: '菜单管理',
      //     icon: 'file',
      //   },
      // },
      {
        path: 'czrz',
        name: 'czrz',
        component: () => import('@/views/personnelManagement/caozuorizhi/index'),
        meta: {
          title: '警令类型管理',
          icon: 'file',
          permissions: ['jllxgl'],
        },
      },

      {
        path: 'deductpoint',
        name: 'deductpoint',
        component: () => import('@/views/personnelManagement/deductPoint/index'),
        meta: {
          title: '扣分项维护',
          icon: 'file',
          permissions: ['deductpoint'],
        },
      },


      {
        path: 'bmfzgl',
        name: 'bmfzgl',
        component: () => import('@/views/personnelManagement/deptGroup/index'),
        meta: {
          title: '部门分组管理',
          icon: 'file',
          permissions: ['bmfzgl'],
        },
      },

      {
        path: 'jqlx',
        name: 'jqlx',
        component: () => import('@/views/personnelManagement/alarmType/index'),
        meta: {
          title: '警情类型管理',
          icon: 'file',
          permissions: ['jqlxgl'],
        },
      },

      {
        path: 'xtrz',
        name: 'xtrz',
        component: () => import('@/views/personnelManagement/loginLog/index'),
        meta: {
          title: '系统日志',
          icon: 'file',
          permissions: ['xtrz'],
        },
      },


    ],
  },  
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})
//注释的地方是允许路由重复点击，如果你觉得框架路由跳转规范太过严格可选择放开
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}
export function resetRouter() {
  router.matcher = new VueRouter({
    base: publicPath,
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  }).matcher
}

export default router
